package com.hualan.sfzyproject.controller.admin;

import com.hualan.sfzyproject.domain.Fm;
import com.hualan.sfzyproject.mapper.FmMapper;
import com.hualan.sfzyproject.service.admin.FmService;
import com.hualan.sfzyproject.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("admin/fm")
public class FMController {
    @Autowired
    private FmMapper fmMapper;
    @Autowired
    private FmService fmService;
    //添加
    @PostMapping
    public R saveFM(@RequestBody Fm fm){
        fmMapper.insert(fm);
        return R.success("添加成功");
    }
    //分页查询全部
    @GetMapping("/page")
    public R getFMList(int page,int pageSize){
        return R.ok(fmService.fmPageQuery(page,pageSize));
    }
    //根据分类id和标题模糊查询
    @GetMapping("/list")
    public R getFMListByCourseTypeId( Long id, String title){
        return R.ok(fmMapper.selectByCourseTypeIdAndTitle(id, title));
    }
    //查询所有分类（以后放在分类controller里）
    @GetMapping("/courseType")
    public R getCourseType(){
        return R.ok(fmMapper.selectAllType());
    }
    //删除
    @DeleteMapping("/{id}")
    public R deleteFM(@PathVariable("id") Long id){
        fmMapper.deleteByFmId(id);
        return R.success("删除成功");
    }
    //修改
    @PutMapping("/{id}")
    public R updateFM(@RequestBody Fm fm){
        fmMapper.updateById(fm);
        return R.success("修改成功");
    }
}
